package com.ruoyi.video.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class StringToLongArrayDeserializer extends JsonDeserializer<long[]> {

    @Override
    public long[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String value = jsonParser.getValueAsString();
        
        // 将字符串按逗号分隔成多个部分
        String[] parts = value.split(",");
        
        // 创建一个 long 数组来保存转换后的值
        long[] longArray = new long[parts.length];
        
        // 将每个部分转换为 long 值并存储到数组中
        for (int i = 0; i < parts.length; i++) {
            longArray[i] = Long.parseLong(parts[i].trim());
        }
        
        return longArray;
    }

    public static void main(String[] args) {

    }
}
